import static java.lang.Thread.sleep;

public class Demo1 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(() -> {//运行时间短
            for (int i = 0; i < 3; i++) {
                System.out.println("Thread1");
                try {
                    sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread thread2 = new Thread(() -> {//运行时间长
            for (int i = 0; i < 3; i++) {
                System.out.println("Thread2");
                try {
                    sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();

        for (int i = 0; i < 3; i++) {
            System.out.println("main");
            sleep(1000);
        }
    }
}
